<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class AboutYou::SDK::Model::Basket - RDoc Documentation</title>

<link href="../../../fonts.css" rel="stylesheet">
<link href="../../../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../../";
</script>

<script src="../../../js/jquery.js"></script>
<script src="../../../js/navigation.js"></script>
<script src="../../../js/search_index.js"></script>
<script src="../../../js/search.js"></script>
<script src="../../../js/searcher.js"></script>
<script src="../../../js/darkfish.js"></script>


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../../../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../../../table_of_contents.html#pages">Pages</a>
    <a href="../../../table_of_contents.html#classes">Classes</a>
    <a href="../../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-create_from_json">::create_from_json</a>
    
    <li ><a href="#method-i-check_additional_data">#check_additional_data</a>
    
    <li ><a href="#method-i-collected_items">#collected_items</a>
    
    <li ><a href="#method-i-delete_all_items">#delete_all_items</a>
    
    <li ><a href="#method-i-delete_item">#delete_item</a>
    
    <li ><a href="#method-i-delete_items">#delete_items</a>
    
    <li ><a href="#method-i-errors-3F">#errors?</a>
    
    <li ><a href="#method-i-item">#item</a>
    
    <li ><a href="#method-i-order_lines_array">#order_lines_array</a>
    
    <li ><a href="#method-i-parse_items">#parse_items</a>
    
    <li ><a href="#method-i-update_item">#update_item</a>
    
    <li ><a href="#method-i-update_item_set">#update_item_set</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-AboutYou::SDK::Model::Basket">
  <h1 id="class-AboutYou::SDK::Model::Basket" class="class">
    class AboutYou::SDK::Model::Basket
  </h1>

  <section class="description">
    
<p>This Class represents a basket model</p>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-i-deleted_items" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">deleted_items</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Array containing the deleted items in the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-errors" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">errors</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>errors of the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-items" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">items</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>array of items in the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-products" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">products</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Array of products</p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_amount" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_amount</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Integer containing the total amount of the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_net" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_net</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Integer containing the total net woth of the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_price" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_price</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Integer containing the total price of the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-total_vat" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">total_vat</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Integer containing the total vat woth of the basket</p>
        
        </div>
      </div>
      
      <div id="attribute-i-unique_variant_count" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">unique_variant_count</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Integer count of unique variants</p>
        
        </div>
      </div>
      
      <div id="attribute-i-updated_items" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">updated_items</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>Array containing the updated items in the basket</p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-create_from_json" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">create_from_json</span><span
            class="method-args">(json_object, factory)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for creating an instance of this class by a
json_object.</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>json_object</code> -&gt; the json_object received from the api</p>
</li><li>
<p><code>factory</code> -&gt; instance of <a
href="../Factory/DefaultModelFactory.html">AboutYou::SDK::Factory::DefaultModelFactory</a></p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="create_from_json-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 39</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">create_from_json</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">factory</span>)
  <span class="ruby-identifier">basket</span> = <span class="ruby-identifier">new</span>
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">errors</span> = {}
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">deleted_items</span> = {}
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">updated_items</span> = {}
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">total_price</span>  = <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'total_price'</span>]
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">total_net</span>    = <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'total_net'</span>]
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">total_vat</span>    = <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'total_vat'</span>]
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">parse_items</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">factory</span>)
  <span class="ruby-identifier">basket</span>.<span class="ruby-identifier">total_amount</span> = <span class="ruby-identifier">items</span>.<span class="ruby-identifier">count</span>

  <span class="ruby-identifier">basket</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-check_additional_data" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">check_additional_data</span><span
            class="method-args">(add_data = nil, _img_url_required = false)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>checks if certain additional_data is valid to set for a basket or not</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>add_data</code> -&gt; the desired data to check</p>
</li><li>
<p><code>_img_url_required</code> -&gt; unused operator</p>
</li></ul>
</li><li>
<p><strong>Fails</strong> :</p>
<ul><li>
<p>if add_data doesnt have a description</p>
</li><li>
<p>if add_data doesnt have valid internal infos</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="check_additional_data-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 297</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">check_additional_data</span>(<span class="ruby-identifier">add_data</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">_img_url_required</span> = <span class="ruby-keyword">false</span>)
  <span class="ruby-identifier">fail</span> <span class="ruby-string">'InvalidArgumentException! description is required
    in additional data'</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">add_data</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">add_data</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-string">'description'</span>)
  <span class="ruby-identifier">fail</span> <span class="ruby-string">'InvalidArgumentException! internal_infos must be an array'</span> <span class="ruby-keyword">if</span>
  <span class="ruby-identifier">add_data</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-string">'internal_infos'</span>) <span class="ruby-operator">&amp;&amp;</span>
  <span class="ruby-operator">!</span><span class="ruby-identifier">add_data</span>[<span class="ruby-string">'internal_infos'</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-collected_items" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">collected_items</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This methods creates a Hash containing pairs of  unique_item_key =&gt;
instance of <a href="BasketItem.html">AboutYou::SDK::Model::BasketItem</a>
It only contains 1 entry per unique_item_key and will increase the amount
if more items are given</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Hash containing pairs of  unique_item_key =&gt; instance of <a
href="BasketItem.html">AboutYou::SDK::Model::BasketItem</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="collected_items-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 86</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">collected_items</span>
  <span class="ruby-identifier">items</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">items</span>
  <span class="ruby-identifier">items_merged</span> = {}
  <span class="ruby-identifier">items</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">key</span> = <span class="ruby-identifier">item</span>.<span class="ruby-identifier">unique_key</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">items_merged</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">key</span>)
      <span class="ruby-identifier">amount</span> = <span class="ruby-identifier">items_merged</span>[<span class="ruby-identifier">key</span>][<span class="ruby-string">'amount'</span>] <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
      <span class="ruby-identifier">items_merged</span>[<span class="ruby-identifier">key</span>] = {
        <span class="ruby-string">'item'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">item</span>,
        <span class="ruby-string">'price'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">total_price</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">amount</span>,
        <span class="ruby-string">'amount'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">amount</span>
      }
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">items_merged</span>[<span class="ruby-identifier">key</span>] = {
        <span class="ruby-string">'item'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">item</span>,
        <span class="ruby-string">'price'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">total_price</span>,
        <span class="ruby-string">'amount'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
      }
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">items_merged</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete_all_items" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">delete_all_items</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for deleting all items from the basket</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="delete_all_items-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 210</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">delete_all_items</span>
  <span class="ruby-identifier">items</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">items</span>

  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">items</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">ids</span> = []
  <span class="ruby-identifier">items</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">ids</span>.<span class="ruby-identifier">push</span> = <span class="ruby-identifier">item</span>.<span class="ruby-identifier">id</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">delete_items</span>(<span class="ruby-identifier">ids</span>)

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete_item" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">delete_item</span><span
            class="method-args">(item_id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for deleting an item from the basket</p>
<ul><li>
<p><strong>Args</strong> :</p>
<ul><li>
<p><code>item_id</code> -&gt; the item_id for which the item should be deleted</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="delete_item-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 181</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">delete_item</span>(<span class="ruby-identifier">item_id</span>)
  <span class="ruby-identifier">deleted_items</span>[<span class="ruby-identifier">item_id</span>] = <span class="ruby-identifier">item_id</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete_items" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">delete_items</span><span
            class="method-args">(item_ids)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for deleting items from the basket</p>
<ul><li>
<p><strong>Args</strong> :</p>
<ul><li>
<p><code>item_ids</code> -&gt; Array containing item ids for which items
should be deleted</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="delete_items-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 196</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">delete_items</span>(<span class="ruby-identifier">item_ids</span>)
  <span class="ruby-identifier">item_ids</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item_id</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">deleted_items</span>[<span class="ruby-identifier">item_id</span>] = <span class="ruby-identifier">item_id</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-errors-3F" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">errors?</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method checks if there are errors in the basket set</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Boolean determining whether there are errors or not</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="errors-3F-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 59</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">errors?</span>
  <span class="ruby-identifier">errors</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-item" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">item</span><span
            class="method-args">(item_id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method gets an item from the basket for a given item id</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>item_id</code> -&gt; the id used for searching in the basket</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>instance of <a href="BasketItem.html">AboutYou::SDK::Model::BasketItem</a>
or null if not found</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="item-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 72</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">item</span>(<span class="ruby-identifier">item_id</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">items</span>[<span class="ruby-identifier">item_id</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">items</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">item_id</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-order_lines_array" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">order_lines_array</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method builds the order lines for the update query</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Array containing either Hashes with pairs of ‘delete’ =&gt; item_id or
instances of <a href="BasketItem.html">AboutYou::SDK::Model::BasketItem</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="order_lines_array-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 117</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">order_lines_array</span>
  <span class="ruby-identifier">order_lines</span> = []

  <span class="ruby-identifier">deleted_items</span>.<span class="ruby-identifier">uniq</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">itemId</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">order_lines</span>.<span class="ruby-identifier">push</span>(<span class="ruby-string">'delete'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">itemId</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">updatedItems</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">order_lines</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">item</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">order_lines</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-parse_items" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">parse_items</span><span
            class="method-args">(json_object, factory)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for parsing the items in the basket</p>
<ul><li>
<p><strong>Args</strong> :</p>
<ul><li>
<p><code>json_object</code> -&gt; the json object received from the api</p>
</li><li>
<p><code>factory</code> -&gt; Instance of <a
href="../Factory/DefaultModelFactory.html">AboutYou::SDK::Factory::DefaultModelFactory</a></p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="parse_items-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 141</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse_items</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">factory</span>)
  <span class="ruby-identifier">products</span> = {}

  <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'products'</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">json_product</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">products</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">create_product</span>(<span class="ruby-identifier">json_product</span>)
  <span class="ruby-keyword">end</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'products'</span>]

  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">products</span> = <span class="ruby-identifier">products</span>
  <span class="ruby-identifier">vids</span> = []

  <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'order_lines'</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">json_item</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_item</span>[<span class="ruby-string">'set_items'</span>]
      <span class="ruby-identifier">item</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">create_basket_set</span>(<span class="ruby-identifier">json_item</span>, <span class="ruby-identifier">products</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">vids</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">json_item</span>[<span class="ruby-string">'variantId'</span>])
      <span class="ruby-identifier">item</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">create_basket_item</span>(<span class="ruby-identifier">json_item</span>, <span class="ruby-identifier">products</span>)
    <span class="ruby-keyword">end</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">errors?</span>
      <span class="ruby-identifier">errors</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">item</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">items</span>[<span class="ruby-identifier">item</span>.<span class="ruby-identifier">id</span>] = <span class="ruby-identifier">item</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'order_lines'</span>]

  <span class="ruby-identifier">vids</span> = <span class="ruby-identifier">vids</span>.<span class="ruby-identifier">uniq</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">uniqueVariantCount</span> = <span class="ruby-identifier">vids</span>.<span class="ruby-identifier">count</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-update_item" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">update_item</span><span
            class="method-args">(basket_item)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for updating an item in the basket</p>
<ul><li>
<p><strong>Args</strong> :</p>
<ul><li>
<p><code>basket_item</code> -&gt; instance of <a
href="BasketItem.html">AboutYou::SDK::Model::BasketItem</a></p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="update_item-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 232</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">update_item</span>(<span class="ruby-identifier">basket_item</span>)
  <span class="ruby-identifier">item</span> = {
    <span class="ruby-string">'id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">basket_item</span>.<span class="ruby-identifier">id</span>,
    <span class="ruby-string">'variant_id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">basket_item</span>.<span class="ruby-identifier">variant_id</span>,
    <span class="ruby-string">'app_id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">basket_item</span>.<span class="ruby-identifier">app_id</span>
  }
  <span class="ruby-identifier">add_data</span> = <span class="ruby-identifier">basket_item</span>.<span class="ruby-identifier">additional_data</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">add_data</span>
    <span class="ruby-identifier">check_additional_data</span>(<span class="ruby-identifier">add_data</span>)
    <span class="ruby-identifier">item</span>[<span class="ruby-string">'additional_data'</span>] = <span class="ruby-identifier">add_data</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">updated_items</span>[<span class="ruby-identifier">basket_item</span>.<span class="ruby-identifier">id</span>] = <span class="ruby-identifier">item</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-update_item_set" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">update_item_set</span><span
            class="method-args">(basket_set)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for updating an item set in the basket</p>
<ul><li>
<p><strong>Args</strong> :</p>
<ul><li>
<p><code>basket_item</code> -&gt; instance of <a
href="BasketSet.html">AboutYou::SDK::Model::BasketSet</a></p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Basket.html">AboutYou::SDK::Model::Basket</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="update_item_set-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/basket.rb, line 257</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">update_item_set</span>(<span class="ruby-identifier">basket_set</span>)
  <span class="ruby-identifier">items</span> = <span class="ruby-identifier">basket_set</span>.<span class="ruby-identifier">items</span>

  <span class="ruby-identifier">fail</span> <span class="ruby-string">'InvalidArgumentException! BasketSet
    needs at least one item'</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">items</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-identifier">item_set</span> = []
  <span class="ruby-identifier">items</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sub_item</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">item</span> = {
      <span class="ruby-string">'variant_id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">sub_item</span>.<span class="ruby-identifier">variant_id</span>,
      <span class="ruby-string">'app_id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">sub_item</span>.<span class="ruby-identifier">app_id</span>
    }
    <span class="ruby-identifier">add_data</span> = <span class="ruby-identifier">sub_item</span>.<span class="ruby-identifier">additional_data</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">add_data</span>
      <span class="ruby-identifier">check_additional_data</span>(<span class="ruby-identifier">add_data</span>)
      <span class="ruby-identifier">item</span>[<span class="ruby-string">'additional_data'</span>] = <span class="ruby-identifier">add_data</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">item_set</span>.<span class="ruby-identifier">push</span> = <span class="ruby-identifier">item</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">updated_items</span>[<span class="ruby-identifier">basket_set</span>.<span class="ruby-identifier">id</span>] = {
    <span class="ruby-string">'id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">basket_set</span>.<span class="ruby-identifier">id</span>,
    <span class="ruby-string">'additional_data'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">basket_set</span>.<span class="ruby-identifier">additional_data</span>,
    <span class="ruby-string">'set_items'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">item_set</span>
  }

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.2.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

